import axios from "axios"
export default {
    namespaced:true,
    state:{
        goodsList:[],
        listImages:"",
        detailImages:[],
        currentPage:1,
        pageSize:3,
        sum:0,
        condition:"number",
        inputInfor:"",
        classify:""
    },
    mutations:{
        getGoodsList(state,payload){          
            state.goodsList=payload.infor;
            state.sum=payload.sum           
        },
        //获取全部数据
        getAllGoodsList(state,payload){        
            state.goodsList=payload           
        },
        //下一页
        nextPage(state){
            state.currentPage++;
        },
        //上一页
        prePage(state){
            if(state.currentPage>1){
                state.currentPage--
            }
        },
        //当每页显示数量改变时
        SizeChange(state,val){
            state.pageSize=val
        },
        //当前页数改变时
        CurrentChange(state,val){
            state.currentPage=val
        },
         //搜索
         switchCondition(state,payload){
            state.condition=payload          
        },
        switchInputInfor(state,payload){
            state.inputInfor=payload
        },
        switchclassify(state,payload){
            state.classify=payload
        },
        //清空inputInfor
        clearInput(state){
            state.inputInfor=""
            state.classify=""
        },
    },
    actions:{
        getGoods(context){
            const  {currentPage,pageSize,condition,inputInfor,classify}=context.state      
            axios
            .get("/goods/getAll",{params:{currentPage,pageSize,condition,inputInfor,classify}})
            .then(res=>{
                context.commit("getGoodsList",res.data)
            })
        },
        //获取全部商品接口
        getAllGoods(context){
            axios
            .get("/goods/getAllGoods")
            .then(res=>{
                context.commit("getAllGoodsList",res.data)
            })
        }
    }
}